package com.ordering.dao.register.impl;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.ordering.dao.register.RegisterDao;
import com.ordering.entity.Message;
import com.ordering.entity.User;
import com.ordering.util.HibernateUtil;

public class RegisterDaoImpl implements RegisterDao
{

    private SessionFactory sessionFactory;
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    
    
    @Override
    public Message msisdnIsAvailable(String msisdn)
    {
        
        return null;
    }

    @Override
    public Message register(User user)
    {
        Session s=null;
        Message returnMessage = new Message();
        returnMessage.setStatus(true);
        try{
            s=HibernateUtil.getSession();
            
            Transaction tran = s.beginTransaction();
            s.save(user);
            tran.commit();
            
        }catch (Exception e) {
            returnMessage.setStatus(false);
            returnMessage.setMessage(e.getMessage());
            e.printStackTrace();
        }finally{
            if(s!=null)
                s.close();
        }
        return returnMessage;
    }

}
